; start.s
; Copyright (c) 2010 Peter Polacik <polacik.p@gmail.com>
;
; This file is part of Beix Operating System
;
; Licensed under MIT License, see COPYRIGHT for more information.
;

[BITS 32]
global start
start:
	mov	esp, _sys_stack
	jmp	bootup

ALIGN 4
mboot:
	MULTIBOOT_PAGE_ALIGN	equ	1<<0
	MULTIBOOT_MEMORY_INFO	equ	1<<1
	MULTIBOOT_AOUT_KLUDGE	equ	1<<16
	MULTIBOOT_HEADER_MAGIC	equ	0x1BADB002
	MULTIBOOT_HEADER_FLAGS	equ	MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
	MULTIBOOT_CHECKSUM	equ	-(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
	EXTERN			code, bss, end

	dd	MULTIBOOT_HEADER_MAGIC
	dd	MULTIBOOT_HEADER_FLAGS
	dd	MULTIBOOT_CHECKSUM

	dd	mboot
	dd	code
	dd	bss
	dd	end
	dd	start

bootup:
	cli
	extern main
	call main
	jmp	$

global gdt_flush
extern gp
gdt_flush:
	lgdt	[gp]
	mov	ax, 0x10
	mov	ds, ax
	mov	es, ax
	mov	fs, ax
	mov	gs, ax
	mov	ss, ax
	jmp	0x08:flush2

flush2:
	ret

SECTION .bss
	resb	8192
_sys_stack:

